#     Xepec.ru - социальная сеть
#     Copyright (C) 2008  Fedorchenko Alexander
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: sos20@list.ru
#     Date: 17/01/2009
#
#
#TODO: Бороться с HTML на перле так же как на PHP #$stat = htmlentities($stat, ENT_NOQUOTES, "UTF-8");
require "core.pl";

sub add_comment
{
	my $autor = do_check();
	my $cat = shift;
	my $item_id = shift;
	my $title = shift;
	my $comment = shift;
	my $level = shift;
	my $date = date_iso8601();
	
	$dbcnx->do(qq{INSERT INTO comments VALUES (0,'$autor', '$date', '$cat', '$item_id', '$title', '$comment', '$level',0)}) or die("Ошибка с сервером xepec.ru #1");
	$ath->finish();
	$dbcnx->disconnect();
	return 1;
}


#print "Content-type: text/plain; charset=utf-8\n\n";
print "Content-Type: text/html; charset=utf-8\n\n";

&get_query();
$cat=$queryString{ "cat" };
$item_id=$queryString{ "item_id" };
$title=$queryString{ "title" };
$comment=$queryString{ "comment" };
$level=$queryString{ "level" };
#$stat="lllllss";
#$stat = htmlentities($stat, ENT_NOQUOTES, "UTF-8");
$cat =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$item_id =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$title =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$comment =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;


add_comment($cat,$item_id,$title,$comment,$level);

#if (change_status($stat))
#{
#	print $stat;
#}
#else
#{
#	print "У нас временные проблемы";
#}